layui.use(['form','table'], function() {
    const form = layui.form
        , table = layui.table;

    //渲染
    var tableVar = table.render({
        elem: '#tableId',
        method: 'post',
        url: contextPath + '/menu/list',
        cols: [ [
            {field: 'serialNumber', align: 'center', title: '序号', type: 'numbers'},
            {field: 'name', align: 'center', title: '菜单名称'},
            {field: 'path', align: 'center', title: '路径'},
            {field: 'icon', align: 'center', title: '图标'},
            {field: 'orderNum', align: 'center', title: '排序号'},
            {field: 'updated', align: 'center', title: '更新时间'},
            {title: '操作', width: 130, align: 'center', toolbar: '#operation'}
        ] ],
        page: true,
        id: 'tableId',
    });
    //搜索
    form.on('submit(searchBtn)', function(data) {
        const field = data.field;
        table.reload('tableId', {
            method: 'post',
            where: field,
            page:{curr:1}
        });
    });
    //新增
    form.on('submit(addBtn)', function() {
        window.open(contextPath+"/menu/add","_self");
    });
    //工具条
    table.on('tool(tableFilter)', function(obj){
        var data = obj.data;
        if (obj.event === "editBtn") {
            window.open(contextPath+"/menu/edit/"+data.id, "_self");
        } else if (obj.event === "delBtn") {
            layer.confirm('确认删除?', {
                btn: ['确定', '取消']
                ,yes: function(index, layero){
                    $.post("/menu/del/"+data.id, {}, function (data) {
                        if (data.status === 200) {
                            console.log("成功返回")
                        }
                        layer.msg(data.msg, {
                            icon: 1,       //信息框与加载层的私有参数
                            time: 1500     //意思是2.5秒后自动关闭
                        }, function () {   //关闭弹出框后执行的函数
                            console.log("后端返回" + data.msg)
                        });
                    });
                }
            }, function(index, layero){
                return false;
            });
        }
    });
    //按钮
    $("#addBtn").click(function(){

    });
});